package com.interview03;

import java.util.concurrent.TimeUnit;

/**
 * Copyright (C), 2018-2020
 * FileName: Demo3
 * Author:   kongfanyu
 * Date:     2020/12/20 08:55
 */
public class Demo3 {
    private static Object obj = new Object();
    public static void main(String[] args) {
        new Thread( () ->{
            System.out.println(Thread.currentThread().getName()+"进入等待状态....");
            try {
                synchronized (obj) {
                    obj.wait();
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName()+"结束等待状态....");

        },"线程A").start();

        try { TimeUnit.SECONDS.sleep(1); } catch (InterruptedException e) { e.printStackTrace(); }

        new Thread( () ->{
            System.out.println(Thread.currentThread().getName()+"开始唤醒....");
            synchronized (obj) {
                obj.notify();
            }
            System.out.println(Thread.currentThread().getName()+"结束唤醒....");

        },"线程B").start();
    }
}
